package shujvjiegou.week8;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @Author JetZhang
 * @Date 2021/10/31
 */
public class T3 {
    private static Queue<TNode> queue_TNode;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] arr = scanner.nextLine().split(" ");
        TNode tree = new TNode(arr[0]);
        for (int i = 1; i < arr.length; i++) {
            new T3().insert(tree, arr[i]);
        }
        new T3().inRootTraverse(tree);
    }

    private void insert(TNode t_node, String s) {
        queue_TNode = new LinkedList<>();
        queue_TNode.add(t_node);
        while (!queue_TNode.isEmpty()) {
            t_node = queue_TNode.poll();
            if (!t_node.data.equals("None")) {
                if (t_node.lChild == null) {
                    t_node.lChild = new TNode(s);
                    break;
                } else
                    queue_TNode.add(t_node.lChild);

                if (t_node.rChild == null) {
                    t_node.rChild = new TNode(s);
                    break;
                } else {
                    queue_TNode.add(t_node.rChild);
                }
            }
        }
    }

    private void inRootTraverse(TNode tree) {
        if (tree != null) {
            if (!tree.data.equals("None")) {
                inRootTraverse(tree.lChild);
                System.out.print(tree.data+" ");
                inRootTraverse(tree.rChild);
            }
        }
    }
}

class TNode {
    TNode lChild;
    TNode rChild;
    String data;

    public TNode(String data) {
        lChild = null;
        rChild = null;
        this.data = data;
    }
}
